package Lambda表达式;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Lambdas排序集合 {
	String[] players = { "Rafael Nadal", "Novak Djokovic", "Stanislas Wawrinka", "David Ferrer", "Roger Federer", "Andy Murray", "Tomas Berdych", "Juan Martin Del Potro", "Richard Gasquet", "John Isner" };
	// 1.1 使用匿名内部类根据 name 排序 players  
	public String[] getPlayers1() {

		Arrays.sort(players, new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				// TODO Auto-generated method stub
				return (o1.compareTo(o2));
			}
		});
		return players;
	}
	// 1.2 使用 lambda expression 排序 players  
	public String[] getPlayers2() {

		//Comparator<String> sortByName = (String s1, String s2) -> (s1.compareTo(s2));  
		//Arrays.sort(players, sortByName); 
		Arrays.sort(players, (String s1, String s2) -> (s1.compareTo(s2)));  

		return players;
	}
	public void setPlayers(String[] players) {
		this.players = players;
	}

	public static void main(String[] args) {
		Lambdas排序集合 lambdas排序集合 = new Lambdas排序集合();
		List<String> newList = Arrays.asList(lambdas排序集合.getPlayers2());
		newList.forEach(System.out::println);
	}
}
